import 'package:flutter/services.dart';
 
class PasswordFormatter extends TextInputFormatter {

  // 中文正则
  static final RegExp _passwordRegExp = RegExp(r'[\u4e00-\u9fa5]');

  @override
  TextEditingValue formatEditUpdate(
      TextEditingValue oldValue, TextEditingValue newValue) {
    if (newValue.text.isNotEmpty && _passwordRegExp.hasMatch(newValue.text)) {
      // 如果匹配，则返回旧值，即不更新输入框内容
      return oldValue;
    }
    return newValue;
  }
}